RedBoxChatEvent

Kind of class:class
Inherits from:SFSEvent
Dispatched by:
Author:The gotoAndPlay() Team
http://www.smartfoxserver.com
http://www.gotoandplay.it
Classpath:com.smartfoxserver.redbox.events.RedBoxChatEvent
File last modified:Monday, 07 July 2008, 11:22:19
RedBoxChatEvent is the class representing all events dispatched by the RedBox's com.smartfoxserver.redbox.AVChatManager instance.
The RedBoxChatEvent extends the it.gotoandplay.smartfoxbits.events.SFSEvent class, which in turn extends the it.gotoandplay.smartfoxbits.events.BaseEvent.
RedBoxChatEvent also provides a public property called params of type Object that can contain any number of parameters.
Usage:
  • Please refer to the specific events for usage examples and params object content.

Summary


Event handlers
  • onAVConnectionInited : String
    • Dispatched when the connection to Red5 server has been established.
  • onAVConnectionError : String
    • Dispatched when the connection to Red5 server can't be established.
  • onRecipientMissing : String
    • Dispatched when a chat request is sent, but the recipient is not available.
  • onDuplicateRequest : String
    • Dispatched when a chat request is sent, but a mutual request has already been sent by the recipient.
  • onChatRequest : String
    • Dispatched when an a/v chat request is received.
  • onChatRefused : String
    • Dispatched when an a/v chat request has been refused by the recipient.
  • onChatStarted : String
    • Dispatched when an a/v chat session is started, after the recipient accepted the requester's invitation.
  • onChatStopped : String
    • Dispatched when an a/v chat session is stopped.

Event handlers

onAVConnectionError

static onAVConnectionError:String = "onAVConnectionError"
(read)

Dispatched when the connection to Red5 server can't be established.
This event is dispatched when an error or special condition (like "connection closed") occurred in the NetConnection object used internally by the com.smartfoxserver.redbox.AVChatManager to handle the connection to Red5.
This kind of error is always related to the Red5 server connection, so you should check if the server is running and reachable.
Also check the Red5 logs or console output for more details.
NOTE: when a connection error occurs, all the existing chat sessions (whatever their status is) are stopped.

The params object contains the following parameters.
Parameters:
errorCode:
(String) the description of the error condition; check the "code" property of the infoObject param of the NetConnection.onStatus handler in the Adobe Flash Media Server ActionScript 2.0 Language Reference.
Example:
  • The following example shows how to handle a Red5 connection error.
    avChatMan.addEventListener(RedBoxChatEvent.onAVConnectionError, Delegate.create(this, onAVConnectionError))
    
    function onAVConnectionError(evt:RedBoxChatEvent):Void
    {
        trace("A connection error occurred: " + evt.params.errorCode)
    }

onAVConnectionInited

static onAVConnectionInited:String = "onAVConnectionInited"
(read)

Dispatched when the connection to Red5 server has been established.
This event is dispatched after the com.smartfoxserver.redbox.AVChatManager is instantiated or when the com.smartfoxserver.redbox.AVChatManager.initAVConnection method is called.
The connection to Red5 must be available before any method related to a/v streaming is called.

No parameters are provided.
Example:
  • The following example shows how to handle the "onAVConnectionInited" event.
    var red5IpAddress:String = "127.0.0.1"
    var avChatMan:AVChatManager = new AVChatManager(red5IpAddress)
    
    avChatMan.addEventListener(RedBoxChatEvent.onAVConnectionInited, Delegate.create(this, onAVConnectionInited))
    
    function onAVConnectionInited(evt:RedBoxChatEvent):Void
    {
        trace("Red5 connection established")
    }

onChatRefused

static onChatRefused:String = "onChatRefused"
(read)

Dispatched when an a/v chat request has been refused by the recipient.

The params object contains the following parameters.
Parameters:
chatSession:
(ChatSession) the com.smartfoxserver.redbox.data.ChatSession object created by the AVChatManager instance when the request was sent.
Example:
  • The following example shows how to handle a chat request refusal.
    avChatMan.addEventListener(RedBoxChatEvent.onChatRefused, Delegate.create(this, onChatRefused))
    
    // The recipient refuses the chat request...
    
    function onChatRefused(evt:RedBoxChatEvent):Void
    {
        var chatData:ChatSession = evt.params.chatSession
    
        trace ("Chat request refused by user" + chatData.mateName)
    
        // Show message and reset start/stop chat buttons states
        ...
    }

onChatRequest

static onChatRequest:String = "onChatRequest"
(read)

Dispatched when an a/v chat request is received.

The params object contains the following parameters.
Parameters:
chatSession:
(ChatSession) the com.smartfoxserver.redbox.data.ChatSession object created by the AVChatManager instance when the request is received.
Example:
  • The following example shows how to handle an incoming chat request.
    avChatMan.addEventListener(RedBoxChatEvent.onChatRequest, Delegate.create(this, onChatRequest))
    
    // Another user sends a chat request...
    
    function onChatRequest(evt:RedBoxChatEvent):Void
    {
        var chatData:ChatSession = evt.params.chatSession
    
        trace ("Chat request received ->" + chatData.toString())
    
        // Enable "accept" and "decline" buttons
        ...
    }

onChatStarted

static onChatStarted:String = "onChatStarted"
(read)

Dispatched when an a/v chat session is started, after the recipient accepted the requester's invitation.
This event is fired on both the requester and the recipient clients.
In order to display the connected users' a/v streams, the com.smartfoxserver.redbox.data.ChatSession.myStream and com.smartfoxserver.redbox.data.ChatSession.mateStream properties should be used. These two properties are set depending on the request type and on who is the requester.
Check the following table:



The params object contains the following parameters.
Parameters:
chatSession:
(ChatSession) the com.smartfoxserver.redbox.data.ChatSession object created by the AVChatManager instance when the request was sent/received.
Example:
  • The following example shows how to handle a chat starting.
    avChatMan.addEventListener(RedBoxChatEvent.onChatStarted, Delegate.create(this, onChatStarted))
    
    // I'm the recipient accepting the chat request...
    avChatMan.acceptChatRequest(chatSessionId)
    
    function onChatStarted(evt:RedBoxChatEvent):Void
    {
        var chatData:ChatSession = evt.params.chatSession
    
        var myStream:NetStream = chatData.myStream
        var mateStream:NetStream = chatData.mateStream
    
        // Attach streams to Video objects on stage
        ...
    }

onChatStopped

static onChatStopped:String = "onChatStopped"
(read)

Dispatched when an a/v chat session is stopped.
This event is not fired on the client of the user who stopped the chat session, but only on his/her mate's client.

The params object contains the following parameters.
Parameters:
chatSession:
(ChatSession) the com.smartfoxserver.redbox.data.ChatSession object created by the AVChatManager instance when the request was sent/received.
Example:
  • The following example shows how to handle a chat being stopped.
    avChatMan.addEventListener(RedBoxChatEvent.onChatStopped, Delegate.create(this, onChatStopped))
    
    avChatMan.stopChat(chatSessionId)
    
    function onChatStopped(evt:RedBoxChatEvent):Void
    {
        var chatData:ChatSession = evt.params.chatSession
    
        // Detach streams from Video objects on stage
        ...
    }

onDuplicateRequest

static onDuplicateRequest:String = "onDuplicateRequest"
(read)

Dispatched when a chat request is sent, but a mutual request has already been sent by the recipient.

The params object contains the following parameters.
Parameters:
chatSession:
(ChatSession) the same com.smartfoxserver.redbox.data.ChatSession object returned by the AVChatManager instance when the com.smartfoxserver.redbox.AVChatManager.sendChatRequest method was called.
Example:
  • The following example shows how to handle the "onDuplicateRequest" event.
    avChatMan.addEventListener(RedBoxChatEvent.onDuplicateRequest, Delegate.create(this, onDuplicateRequest))
    
    avChatMan.sendChatRequest(AVChatManager.REQ_TYPE_SEND_RECEIVE, buddyId, true, true)
    
    function onDuplicateRequest(evt:RedBoxChatEvent):Void
    {
        trace ("Request '" + evt.params.chatSession.id + "' error: a mutual request has already been sent by the recipient!")
    }

onRecipientMissing

static onRecipientMissing:String = "onRecipientMissing"
(read)

Dispatched when a chat request is sent, but the recipient is not available.

The params object contains the following parameters.
Parameters:
chatSession:
(ChatSession) the same com.smartfoxserver.redbox.data.ChatSession object returned by the AVChatManager instance when the com.smartfoxserver.redbox.AVChatManager.sendChatRequest method was called.
Example:
  • The following example shows how to handle the "onRecipientMissing" event.
    avChatMan.addEventListener(RedBoxChatEvent.onRecipientMissing, Delegate.create(this, onRecipientMissing))
    
    avChatMan.sendChatRequest(AVChatManager.REQ_TYPE_SEND_RECEIVE, buddyId, true, true)
    
    function onRecipientMissing(evt:RedBoxChatEvent):Void
    {
        trace ("Request '" + evt.params.chatSession.id + "' error: the recipient is not available!")
    }